﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WCell.Constants;

namespace WCell.RealmServer.Gossips
{
	/// <summary>
	/// Represents action (battlemaster, flightmaster, etc.) gossip item in menu
	/// </summary>
	public class GossipMenuItem
	{
		public GossipMenuIcon Icon;
		public string Text;
		public int RequiredMoney;
		public byte Input;

		/// <summary>
		/// If set, will show an Accept/Cancel dialog with this text to the player
		/// when selecting this Item.
		/// </summary>
		public string ConfirmText;

		/// <summary>
		/// Determines if character is elligible for viewing this item and action taken on item selection
		/// </summary>
		public IGossipAction Action;

		public GossipMenuItem()
		{
			Text = string.Empty;
			ConfirmText = string.Empty;
		}

		public GossipMenuItem(GossipMenuIcon type, string text)
		{
			Icon = type;
			Text = text;
			ConfirmText = string.Empty;
		}

		public GossipMenuItem(string text)
			: this(GossipMenuIcon.Talk, text)
		{
		}

		public GossipMenuItem(string text, IGossipAction action)
			: this(text)
		{
			Action = action;
		}

		public GossipMenuItem(string text, GossipActionHandler callback)
			: this(text)
		{
			Action = new DefaultGossipAction(callback);
		}

		public GossipMenuItem(string text, GossipActionHandler callback, string confirmText)
			: this(text)
		{
			ConfirmText = confirmText;
			Action = new DefaultGossipAction(callback);
		}

		public GossipMenuItem(string text, GossipActionHandler callback, params GossipMenuItem[] items)
			: this(text)
		{
			Action = new DefaultGossipAction(callback);
			SubMenu = new GossipMenu(items);
		}

		public GossipMenuItem(string text, GossipMenu subMenu)
			: this(text, (IGossipAction)null, subMenu)
		{
		}

		public GossipMenuItem(string text, GossipActionHandler callback, GossipMenu subMenu)
			: this(text)
		{
			Action = new DefaultGossipAction(callback);
			SubMenu = subMenu;
		}

		public GossipMenuItem(string text, IGossipAction action, GossipMenu subMenu)
			: this(text)
		{
			Action = action;
			SubMenu = subMenu;
		}

		public GossipMenuItem(string text, params GossipMenuItem[] items)
			: this(text)
		{
			SubMenu = new GossipMenu(items);
		}

		public GossipMenuItem(GossipMenuIcon icon, string text, params GossipMenuItem[] items)
			: this(text)
		{
			Icon = icon;
			SubMenu = new GossipMenu(items);
		}

		public GossipMenuItem(GossipMenuIcon icon, string text, IGossipAction action)
			: this(text)
		{
			Icon = icon;
			Action = action;
		}

		public GossipMenuItem(GossipMenuIcon icon, string text, GossipActionHandler callback)
			: this(text)
		{
			Icon = icon;
			Action = new DefaultGossipAction(callback);
		}

		/// <summary>
		/// The <see cref="GossipMenu"/> to be shown when selecting this Item
		/// </summary>
		public GossipMenu SubMenu
		{
			get;
			set;
		}

		public void SetAction(DefaultGossipAction action)
		{
			Action = action;
		}
	}

	public class QuitGossipMenuItem : GossipMenuItem
	{
		public QuitGossipMenuItem(GossipMenuIcon type, string text)
			: base(type, text)
		{
		}

		public QuitGossipMenuItem(string text)
			: base(text)
		{
			Action = new DefaultGossipAction((convo) => {
				convo.Character.GossipConversation.StayOpen = false;
			});
		}

		public QuitGossipMenuItem(string text, GossipActionHandler callback) :
			base(text)
		{
			Action = new DefaultGossipAction((convo) => {
				convo.Character.GossipConversation.StayOpen = false;
				callback(convo);
			});
		}

		public QuitGossipMenuItem(string text, GossipActionHandler callback, string confirmText)
			: base(text)
		{
			ConfirmText = confirmText;
			Action = new DefaultGossipAction((convo) => {
				convo.Character.GossipConversation.StayOpen = false;
				callback(convo);
			});
		}

		public QuitGossipMenuItem(string text, GossipActionHandler callback, params GossipMenuItem[] items)
			: base(text, items)
		{
			Action = new DefaultGossipAction((convo) => {
				convo.Character.GossipConversation.StayOpen = false;
				callback(convo);
			});
		}

		public QuitGossipMenuItem(string text, GossipMenu subMenu)
			: base(text, subMenu)
		{
			Action = new DefaultGossipAction((convo) => {
				convo.Character.GossipConversation.StayOpen = false;
			});
		}

		public QuitGossipMenuItem(string text, GossipActionHandler callback, GossipMenu subMenu)
			: base(text, subMenu)
		{
			Action = new DefaultGossipAction((convo) => {
				convo.Character.GossipConversation.StayOpen = false;
				callback(convo);
			});
		}

		public QuitGossipMenuItem(string text, params GossipMenuItem[] items)
			: base(text, items)
		{
			Action = new DefaultGossipAction((convo) => {
				convo.Character.GossipConversation.StayOpen = false;
			});
		}

		public QuitGossipMenuItem(GossipMenuIcon icon, string text, params GossipMenuItem[] items)
			: base(icon, text, items)
		{
			Action = new DefaultGossipAction((convo) => {
				convo.Character.GossipConversation.StayOpen = false;
			});
		}

		public QuitGossipMenuItem(GossipMenuIcon icon, string text, GossipActionHandler callback)
			: base(icon, text)
		{
			Action = new DefaultGossipAction((convo) => {
				convo.Character.GossipConversation.StayOpen = false;
				callback(convo);
			});
		}
	}

	/// <summary>
	/// Represents quest item in menu
	/// </summary>
	public class QuestMenuItem
	{
		public uint ID;
		public uint Status;
		public uint Level;
		public string Text;

		public QuestMenuItem()
		{
			Text = string.Empty;
		}

		public QuestMenuItem(uint id, uint status, uint level, string text)
		{
			ID = id;
			Status = status;
			Text = text;
			Level = level;
		}
	}
}
